import { Size } from "cc"
import { view } from "cc"
import { _decorator, Component, Node, screen } from "cc"
const { ccclass, property } = _decorator

@ccclass("UpdateAdapter")
export class UpdateAdapter extends Component {
  @property(Node)
  nodeBg: Node = null

  @property(Node)
  nodeProgress: Node = null

  protected onEnable() {
    this.updateAdapter()
    view.on("canvas-resize", this.updateAdapter, this)
  }
  protected onDisable(): void {
    view.on("canvas-resize", this.updateAdapter, this)
  }
  private updateAdapter() {
    let winSize = new Size(screen.windowSize.width / view["_scaleX"], screen.windowSize.height / view["_scaleY"])
    this.node.scaleXYZ = winSize.width > winSize.height ? 1 : 1.5
    // this.nodeBg.scaleXYZ = winSize.width > winSize.height ? 1 : 2
    this.nodeProgress.positionY = winSize.width > winSize.height ? -371.477 : -750

    if (winSize.width > winSize.height) {
      this.nodeBg.scaleXYZ = 1
      this.nodeBg.angle = 0
    } else {
      this.nodeBg.scaleXYZ = winSize.height / winSize.width + 0.5
    }
  }
}
